﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using psafth.Common.Extensions;

namespace psafth.AMB
{
    public class Passing
    {
        /// <summary>
        /// Decoder from which the message was sent
        /// </summary>
        public int DecoderId
        {
            get;
            private set;
        }

        /// <summary>
        /// Id of the Transponder
        /// </summary>
        public int TransponderId
        {
            get;
            private set;
        }

        /// <summary>
        /// The which the transponder passed the antenna
        /// </summary>
        public DateTime PassingTime
        {
            get;
            private set;
        }

        /// <summary>
        /// The which the transponder passed the antenna (UTC)
        /// </summary>
        public DateTime UTC
        {
            get;
            private set;
        }

        /// <summary>
        /// Signal strength of the transponder
        /// </summary>
        public double SignalStrength
        {
            get;
            private set;
        }

        /// <summary>
        /// Number of times the decoder recognized the transponder, while passing the antenna
        /// </summary>
        public int Hits
        {
            get;
            private set;
        }

        /// <summary>
        /// The voltage of the transponder (RC4)
        /// </summary>
        public double Voltage
        {
            get;
            private set;
        }

        /// <summary>
        /// The temperature of the transponder (RC4)
        /// </summary>
        public double Temperature
        {
            get;
            private set;
        }

        /// <summary>
        /// Constructor for the PassingObject
        /// </summary>
        /// <param name="fieldOfRecords"></param>
        public Passing(List<DataRowObject> fieldOfRecords)
        {
            foreach (DataRowObject record in fieldOfRecords)
            {
                switch (record.DataType)
                {
                    case (int)AMBGeneralFOR.DECODER_ID:
                        if (record.Data != null)
                            this.DecoderId = record.Data.ToInt32();
                        break;

                    case (int)AMBPassingFOR.TRANSPONDER:
                        if (record.Data != null)
                            this.TransponderId = record.Data.ToInt32();
                        break;

                    case (int)AMBPassingFOR.RTC_TIME:
                        this.PassingTime = AMBCalculator.GetPassingTime(record.Data);
                        break;

                    case (int)AMBPassingFOR.UTC_TIME:
                        this.UTC = AMBCalculator.GetPassingTime(record.Data);
                        break;

                    case (int)AMBPassingFOR.STRENGTH:
                        if (record.Data != null)
                            this.SignalStrength = record.Data.ToInt32();
                        break;

                    case (int)AMBPassingFOR.VOLTAGE:
                        if (record.Data != null)
                            this.Voltage = record.Data.ToInt32() / 10;
                        break;

                    case (int)AMBPassingFOR.HITS:
                        if (record.Data != null)
                            this.Hits = record.Data.ToInt32();
                        break;

                    case (int)AMBPassingFOR.TEMPERATURE:
                        if (record.Data != null)
                            this.Temperature = record.Data.ToInt32() - 100;
                        break;
                }
            }
        }
    }
}
